package com.hotel.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Set;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hotel.dao.DeptMapper;
import com.hotel.dao.IdTypeMapper;
import com.hotel.dao.PositionMapper;
import com.hotel.dao.UserMapper;
import com.hotel.entity.Dept;
import com.hotel.entity.IdType;
import com.hotel.entity.Position;
import com.hotel.entity.User;
import com.hotel.service.UserService;

@Service("userService")
@Transactional(transactionManager="txManager")
public class UserServiceImpl implements UserService {
	
	@Resource
	private UserMapper userMapper;
	
	@Resource
	private IdTypeMapper idTypeMapper;
	
	@Resource
	private DeptMapper deptMapper;
	
	@Resource
	private PositionMapper positionMapper;

	@Override
	public List<User> findAllUser(Integer pageNo,Integer pageSize) {
		return userMapper.findAllUser((pageNo-1)*pageSize,pageSize);
	}
	
	@Override
	public User getByUserName(String email) {
		return userMapper.getByUserName(email);
	}
	
	@Override
	public Set<String> getRoles(String email) {
		return userMapper.getRoles(email);
	}
	
	@Override
	public Set<String> getPermissions(String email) {
		return userMapper.getPermissions(email);
	}

	@Override
	public List<IdType> findAllIdType() {
		List<IdType> idIypeList = idTypeMapper.findAllIdType();
		return idIypeList;
	}

	@Override
	public List<Dept> findAllDept() {
		return deptMapper.findAllDept();
	}

	@Override
	public List<Position> findPositionByDeptId(Integer deptId) {
		return positionMapper.findPositionByDeptId(deptId);
	}

	@Override
	public int insert(User record) {
		SimpleDateFormat sdf =   new SimpleDateFormat( " yyyy-MM-dd HH:mm:ss " );
		Date date = new Date();
		String entryTime = sdf.format(date);
		record.setEntryTime(entryTime);
		return userMapper.insert(record);
	}

	@Override
	public Dept findDeptByPositionId(Integer positionId) {
		return deptMapper.findDeptByPositionId(positionId);
	}

	@Override
	public int updateByPrimaryKey(User record) {
		return userMapper.updateByPrimaryKey(record);
	}

	@Override
	public int deleteByPrimaryKey(Integer userId) {
		return userMapper.deleteByPrimaryKey(userId);
	}
	
	

}
